package com.wy.android.mp;

import com.wy.android.mp.fileupload.FileUploadActivity;
import com.wy.android.mp.infocollect.InfoCollectActivity;
import com.wy.android.mp.infoquery.InfoQueryActivity;
import com.wy.android.mp.location.GpsLocationActivity;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 主界面
 * */

public class MainActivity extends ListActivity {
	
	private Button exitButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.mainmenu);
		setTitle("移动警务通客户端");
		
		
		String[] menus={"信息查询","信息收集","文件上传","GPS定位功能"};
		
		setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,menus));
		getListView().setTextFilterEnabled(true);
		//过滤作用
		
		final AlertDialog.Builder builder=new Builder(this);
		exitButton=(Button) findViewById(R.id.exitButton);
		exitButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				builder.setIcon(R.drawable.tools);
				builder.setTitle("提示对话框");
				builder.setMessage("确定要退出本系统？");
				builder.setPositiveButton("确定",new DialogInterface.OnClickListener() {
			
					public void onClick(DialogInterface dialog, int which) {
						//android.os.Process.killProcess(android.os.Process.myPid());
						System.exit(0);
						
					}
				});
				builder.setNegativeButton("取消",new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
					
					}
				});
				AlertDialog alertDialog=builder.create();
		    	alertDialog.show();
				
			}
		});
		
		Intent intent=getIntent();
		Bundle data=intent.getExtras();
		
		String msg=data.getString("msg");
		if(msg!=null&&!msg.equals("")){
		Toast.makeText(MainActivity.this,msg,Toast.LENGTH_LONG).show();
		}
	//	Toast.makeText(MainActivity.this,msg,Toast.LENGTH_LONG).show();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Intent intent=null;
		
		switch(position){
		
		case 0:
			intent=new Intent(MainActivity.this,InfoQueryActivity.class);
			startActivity(intent);
			break;
		case 1:
			intent=new Intent(MainActivity.this,InfoCollectActivity.class);
			startActivity(intent);
			break;
		case 2:
			intent=new Intent(MainActivity.this, FileUploadActivity.class);
			startActivity(intent);
			break;
		case 3:
			intent=new Intent(MainActivity.this,GpsLocationActivity.class);
			startActivity(intent);
			break;
		}
		
	}
	
	
	
	
	

}
